package com.dtw.ditouwang.ui.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.MyMedalBean;
import com.dtw.ditouwang.repositories.UserRepository;
import com.dtw.ditouwang.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MedalActivity extends BaseActivity {
    MedalGroupAdapter medalGroupAdapter;
    List<MyMedalBean.DataBeanX> medalGroutList = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_medal);
        enableBack();
        setTitle("勋章");
        RecyclerView recyclerView = findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        medalGroupAdapter = new MedalGroupAdapter(medalGroutList);
        recyclerView.setAdapter(medalGroupAdapter);
        webApi.getMyMedal(UserRepository.getInstance().getUserID()).enqueue(new Callback<MyMedalBean>() {
            @Override
            public void onResponse(Call<MyMedalBean> call, Response<MyMedalBean> response) {
                if (response.body().isResult()) {
                    medalGroutList.clear();
                    medalGroutList.addAll(response.body().getData());
                    medalGroupAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(Call<MyMedalBean> call, Throwable t) {
                Log.i("dtw", t.getMessage());
            }
        });
    }
}
